
import traceback
from django.utils import simplejson
from django.http import HttpResponse
import logging

log = logging.getLogger(__name__)

def as_json(handler):
    def makejson(*args, **kwargs):
        try:
            r = handler(*args, **kwargs)
            status = 200
        except Exception, err:
            # fixme: hook into django's notification service
            # log.exception("in JSON response")
            # r = {
            #     'success':False,
            #     'error': repr(err),
            #     'traceback': traceback.format_exc()
            # }
            
            # until above is sorted out, just raise
            raise
            
            status = 500
        return HttpResponse(simplejson.dumps(r), 
                            mimetype='application/json', 
                            status=status )
    return makejson